package com.atguigu.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.base.BaseController;
import com.atguigu.entity.Dict;
import com.atguigu.result.Result;
import com.atguigu.service.DictService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author lhh
 * @ClassName DictController
 * @date 2022/9/17 9:46
 */

@Controller
@RequestMapping("/dict")
public class DictController {

    @Reference
    private DictService dictService;

    @GetMapping
    public String index(){
        return "dict/index";
    }

    @GetMapping("/findZnodes")
    @ResponseBody
    public Result findZnodes(@RequestParam(value = "id",defaultValue = "0") Long id){
        List<Map<String, Object>> znodes = dictService.findZnodes(id);
        return Result.ok(znodes);
    }

    @GetMapping("findListByDictCode/{dictCode}")
    @ResponseBody
    public Result findListByDictCode(@PathVariable String dictCode){
        List<Dict> list = dictService.findListByDictCode(dictCode);
        return Result.ok(list);
    }

    @GetMapping("findListByParentId/{id}")
    @ResponseBody
    public Result findListByParentId(@PathVariable Long id){
        List<Dict> list = dictService.findListByParentId(id);
        return Result.ok(list);
    }
}
